-- Delete inprod detail of duplicate product
DELETE FROM InProdDetail
WHERE ProductId IN (SELECT Id
					FROM Product
					WHERE (Product.LatestInputPrice IS NULL OR Product.SalePrice IS NULL OR Product.SalePrice = 0)
					AND EXISTS (SELECT 1 FROM Product Product2
									WHERE Product2.Id <> Product.Id
									AND Product.[Name] = Product2.[Name]))

-- Delete duplicate product
DELETE 
FROM Product
WHERE (Product.LatestInputPrice IS NULL OR Product.SalePrice IS NULL OR Product.SalePrice = 0)
AND EXISTS (SELECT 1 FROM Product Product2
				WHERE Product2.Id <> Product.Id
				AND Product.[Name] = Product2.[Name])
				
ALTER TABLE [Product] WITH NOCHECK
ADD CONSTRAINT UNQ_Product_Name UNIQUE([Name])